package com.future.order.controller;

import com.annotation.aop.MyLog;
import com.annotation.service.MyLogService;
import com.future.CommonResult;
import com.future.env.EvnContextHolder;
import com.future.order.OrderDO;
import com.future.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RequestMapping("/api/order/")
@RestController
public class OrderController {

    @Value("${server.port}")
    private String port;

    @Value("${order.timeout}")
    private String timeout;

    @Autowired
    private OrderService orderService;

    @Autowired
    private MyLogService myLogService;

    @GetMapping("/get")
    public CommonResult<OrderDO> getOrder() {
        OrderDO orderDO = new OrderDO();
        return CommonResult.success(orderDO);
    }

    @PutMapping("/create")
    public OrderDO create(@RequestBody OrderDO order) {
        return orderService.create(order);
    }

    @MyLog
    @GetMapping("/test-annotation")
    public void testCustomAnnotation() {
        log.info("test custom annotation");
        myLogService.record();
    }

    @GetMapping("/test-env")
    public void testEnvWebFilter() {
        String tag = EvnContextHolder.getTag();
        log.info("tag = {}", tag);
    }

    /**
     * 验证负载均衡
     * @return
     */
    @GetMapping("/port")
    public CommonResult<String> getPort() {
        log.info("get port:{}", port);
        return CommonResult.success(port);
    }
}
